let comment_vm = new Vue({
    el: "#app",
    data: {
        boke: {},
        arr: []//装所有评论的数组
    },
    created: function () {
        let id = location.search.split("=")[1];
        axios.get("/selectById?id=" + id).then(function (response) {
            vm.boke = response.data;
            vm.boke.created = moment(vm.boke.created).format("YYYY年MM月DD日 HH时mm分ss秒");
        })
        axios.get("/comment/selectBybokeId?id=" + id).then(function (response) {
            vm.arr = response.data;
            for (let comment of vm.arr) {
                comment.created = moment(comment.created).format("YYYY年MM月DD日 HH时mm分ss秒")
            }
        })
    },
    methods: {
        comment: function () {
            let data = new FormData(document.querySelector("form"));
            if (data.get("content") == "") {
                alert("评论不能为空");
                return;
            }
            let id = location.search.split("=")[1];
            data.set("bokeId", id)
            axios.post("/comment", data).then(function (response) {
                if (response.data == 1) {
                    alert("评论完成!");
                    location.reload();
                } else {
                    alert("请先登录后再评论!");
                    location.href = "/login.html";
                }
            })
        }
    }
})